import http from "./http";
/** 保存视图数据 */
export const saveLlmView = async (data: Visualization) => {
    return http.post<Visualization[]>(
        import.meta.env.VITE_LLM_API_API + `/save_visualization`,
        { data }
    );
};

/** 获取视图数据 */
export const getLlmView = async (project_id: number) => {
    return http.get<string[]>(
        import.meta.env.VITE_LLM_API_API + `/load_visualization`,
        { params: { project_id } }
    );
};


/** 获取文档列表 */
export const documentList = async (documentName: string) => {
    return http.get<ProjectInfo[]>(
        import.meta.env.VITE_LLM_API_API + `/document_list`,
        { params: { documentName } }
    );
};

/** 删除文档 */
export const documentDelete = async (id: number) => {
    return http.delete(
        import.meta.env.VITE_LLM_API_API + `/document_delete`,
        { params: { id } }
    );
};

/** 新建文档 */
export const documentCreate = async (documentName: string) => {
    return http.post(
        import.meta.env.VITE_LLM_API_API + `/document_create`,
        { data: { documentName } }
    );
};

/** 修改文档 */
export const documentUpdate = async (id: number, documentName: string) => {
    return http.put(
        import.meta.env.VITE_LLM_API_API + `/document_update`,
        { data: { id, documentName } }
    );
};

/** 获取向量数据 */
export const llm_embedding = async (params: LlmEmbedding) => {
    return http.get<LlmEmbeddingResult[]>(
        import.meta.env.VITE_LLM_API_API + `/vector_database`,
        {
            params
        }
    );
};

/** 删除向量数据 */
export const delete_embedding = async (id: number) => {
    return http.delete(
        import.meta.env.VITE_LLM_API_API + `/vector_database_delete`,
        {
            params: { id }
        }
    );
};

/** 修改向量数据 */
export const update_embedding = async (data: DatabaseUpdate) => {
    return http.put(
        import.meta.env.VITE_LLM_API_API + `/vector_database_update`,
        {
            data: data
        }
    );
};

/** 创建向量数据 */
export const create_embedding = async (data: DatabaseCreate) => {
    return http.post(
        import.meta.env.VITE_LLM_API_API + `/vector_database_create`,
        {
            data: data
        }
    );
};

/** html转markdown保存向量数据库 */
export const html_markdown = async (data: HtmlMarkdown) => {
    return http.post(
        import.meta.env.VITE_LLM_API_API + `/html_markdown`,
        {
            data: { ...data }
        }
    );
};

/** 精细分块 */
export const split_data = async (text: string, level: number) => {
    return http.post<string[]>(
        import.meta.env.VITE_LLM_API_API + `/split`,
        {
            data: { text, level }
        }
    );
};

/** 获取文档列表 */
export const projectList = async (projectName?: string) => {
    return http.get<ProjectData[]>(
        import.meta.env.VITE_LLM_API_API + `/project_list`,
        {
            params: { projectName }
        }
    );
};

/** 删除项目 */
export const projectDelete = async (id: number) => {
    return http.delete(
        import.meta.env.VITE_LLM_API_API + `/project_delete`,
        { params: { id } }
    );
};

/** 新建项目 */
export const projectCreate = async (documentName: string, describe?: string) => {
    return http.post(
        import.meta.env.VITE_LLM_API_API + `/project_create`,
        { data: { documentName, describe } }
    );
};

/** 修改项目 */
export const projectUpdate = async (id: number, documentName: string, describe?: string) => {
    return http.put(
        import.meta.env.VITE_LLM_API_API + `/project_update`,
        { data: { documentName, id, describe } }
    );
};


/** 获取基础配置 */
export const getBaseConfig = async () => {
    return http.get<BaseConfig>(
        import.meta.env.VITE_LLM_API_API + `/get_llm_model`
    );
};

/** 获取基础配置 */
export const putBaseConfig = async (baseConfig: BaseConfig) => {
    return http.put(
        import.meta.env.VITE_LLM_API_API + `/update_llm_model`,
        { data: baseConfig }
    );
};

/** 获取日志 */
export const view_log = async (id: number) => {
    return http.get<LogList>(
        import.meta.env.VITE_LLM_API_API + `/view_log`,
        { params: { id } }
    );
};

/** 知识图谱 */
export const atlasList = async (params: Atlas) => {
    return http.get(
        import.meta.env.VITE_LLM_API_API + `/atlas`,
        { params: params }
    );
};

/** 文本分块 */
export const textSegmentation = async (data: Chunk) => {
    return http.post<any>(
        import.meta.env.VITE_LLM_API_API + `/text_segmentation`,
        { data }
    );
};

/** 获取数据集列表 */
export const getDataSetList = async (name?: string) => {
    return http.get<DataSet[]>(
        import.meta.env.VITE_LLM_API_API + `/data_set_list`,
        { params: { name } }
    );
};

/** 新增数据集 */
export const createDataSet = async (data: DataSet) => {
    return http.post(
        import.meta.env.VITE_LLM_API_API + `/data_set_create`,
        { data }
    );
};

/** 更新数据集 */
export const updateDataSet = async (data: DataSet) => {
    return http.put(
        import.meta.env.VITE_LLM_API_API + `/data_set_update`,
        { data }
    );
};

/** 删除数据集 */
export const deleteDataSet = async (id: number) => {
    return http.delete(
        import.meta.env.VITE_LLM_API_API + `/data_set_delete`,
        { params: { id } }
    );
};

// 字典列表
export const getDictionary = async (key: string) => {
    return http.get<Dictionary>(
        import.meta.env.VITE_LLM_API_API + `/dictionary`,
        { params: { key } }
    );
};

// 字典列表
export const getDictionaryList = async (key?: string) => {
    return http.get<Dictionary[]>(
        import.meta.env.VITE_LLM_API_API + `/dictionary_list`,
        { params: { key } }
    );
};

// 字典新增
export const createDictionary = async (data: Dictionary) => {
    return http.post(
        import.meta.env.VITE_LLM_API_API + `/dictionary`,
        { data }
    );
};

// 字典修改
export const updateDictionary = async (data: Dictionary) => {
    return http.put(
        import.meta.env.VITE_LLM_API_API + `/dictionary`,
        { data }
    );
};

// 字典删除
export const deleteDictionary = async (id: number) => {
    return http.delete(
        import.meta.env.VITE_LLM_API_API + `/dictionary`,
        { params: { id } }
    );
};

// 任务配置列表
export const tuningList = async (name: string) => {
    return http.get<LlmTuning[]>(
        import.meta.env.VITE_LLM_API_API + `/tuning_list`,
        { params: { name } }
    );
};

// 任务配置创建
export const tuningCreate = async (data: LlmTuning) => {
    return http.post(
        import.meta.env.VITE_LLM_API_API + `/tuning_create`,
        { data }
    );
};

// 任务配置删除
export const tuningDelete = async (id: number) => {
    return http.delete(
        import.meta.env.VITE_LLM_API_API + `/tuning_delete`,
        { params: { id } }
    );
};

// 任务配置修改
export const tuningUpdate = async (data: LlmTuning) => {
    return http.put(
        import.meta.env.VITE_LLM_API_API + `/tuning_update`,
        { data }
    );
};

// 微调训练
export const training = async (id: number) => {
    return http.get(
        import.meta.env.VITE_LLM_API_API + `/training`,
        { params: { id } }
    );
};

// 微调日志
export const trainingLog = async (id: number) => {
    return http.get(
        import.meta.env.VITE_LLM_API_API + `/training_log`,
        { params: { id } }
    );
};

// 登陆
export const login = async (data: LoginType) => {
    return http.post(
        import.meta.env.VITE_LLM_API_API + `/login`,
        { data }
    );
};

// 创建用户
export const createUser = async (data: UserData) => {
    return http.post(
        import.meta.env.VITE_LLM_API_API + `/user`,
        { data }
    );
};

// 获取用户
export const getUser = async (id: number) => {
    return http.get(
        import.meta.env.VITE_LLM_API_API + `/user/${id}`
    );
};

// 更新用户
export const updateUser = async (data: UserData) => {
    return http.put(
        import.meta.env.VITE_LLM_API_API + `/user`,
        { data }
    );
};

// 删除用户
export const deleteUser = async (id: number) => {
    return http.delete(
        import.meta.env.VITE_LLM_API_API + `/user/${id}`
    );
};

// 列出用户
export const listUsers = async (params) => {
    return http.get<UserData[]>(
        import.meta.env.VITE_LLM_API_API + `/users`,
        { params }
    );
};

// 列出用户
export const nodeRun = async (data: NodeRun) => {
    return http.post<string>(
        import.meta.env.VITE_LLM_API_API + `/node_run`,
        { data }
    );
};

// 获取ollama模型数据
export const getOllamaModel = async () => {
    return http.get(
        import.meta.env.VITE_OLLAMA_URL + `/api/tags`
    );
}